# include <iostream>
# include <string>
# include <map>
# include <cstdio>
# include <cstring>
const int maxn = 10005;
int first;
int next[maxn];
bool isfirst[maxn];
int Id, n;
std::map<std::string , int > m;
std::map<int, std::string> mm;
int main()
{
    freopen("C-large.in", "r", stdin);
    freopen("C-large.txt", "w", stdout);
    int T;
    std::cin >> T;
    for (int ica = 1; ica <= T; ++ica) {
        Id = 1;
        std::cin >> n;
        std::string x, y;
        memset(isfirst, true, sizeof(isfirst));
        memset(next, -1, sizeof(next));
        m.clear(); mm.clear();
        for (int i = 1; i <= n; ++i) {
            std::cin >> x >> y;
            if (!m[x]) m[x] = Id, mm[Id] = x, ++Id;
            if (!m[y]) m[y] = Id, mm[Id] = y, ++Id;
            next[ m[x] ] = m[y];
            isfirst[ m[y] ] = false;
        }
        for (int i = 1; i < Id; ++i) {
            if (isfirst[i]) {
                first = i;
                break;
            }
        }
        int c = first;
        std::cout << "Case #" << ica << ":";
        while (next[c] != -1) {
            std::cout << " " << mm[ c ] << "-" << mm[ next[c] ];
            c = next[c];
        }
        std::cout << std::endl;
    }
    return 0;
}
